#include <stdio.h>

#include <string.h>

char *strstr_r(char *s, char *d, int offset)
{
	char *s1, *s2;
	int l1, l2;
	
	if (s == NULL || d == NULL || (s-offset) == NULL)	return NULL;
	
	l2 = strlen(d);
	if (l2 <= 0)	return NULL;
	l1 = strlen(s-offset);
	if (l1 < offset || offset <= 0) return NULL;
	
	s1 = s;
	s2 = d;
	int i = 0;
	s1 = s1 - l2;
	while ((s-s1)<=offset) {
		if (!memcmp(s1,s2,l2))
			return (char *) s1;
		s1--;
	}
	return NULL;
}


int main()
{

	char str1[20]={"1234231431245123"};
	char *loc = NULL;
	char *str2 = str1 + 6;
	printf("the str2:%s\n", str2);
	loc = strstr_r(str2, "34", str2-str1);
	if (loc == NULL) {
		printf("not found!\n");
	} else {
		printf("make it\n");
		printf("%s\n", loc);
	}
}
